TASK_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

include ../../config.mk

# Inputs
RMD_FILE := $(TASK_DIR)/src/gen_RI_table.Rmd
BASIC_REG_RESULTS_FILE := $(TASK_DIR)/../../run_regressions/output/regression_output__basic.csv
BASIC_BY_SUB_REG_RESULTS_FILE := $(TASK_DIR)/../../run_regressions/output/regression_output__by_subgroup.csv
RI_REG_RESULTS_FILE := $(TASK_DIR)/../../run_stata_regressions/output/randomization_inference/regressions_xsection_RI.csv
RI_BY_PATH_REG_RESULTS_FILE := $(TASK_DIR)/../../run_stata_regressions/output/randomization_inference/regressions_xsection_by_pathway_RI.csv

# One of the outputs
OUT_FILE := $(OUT_DIR)/randomization_inference_up_to_date.tex

$(OUT_FILE): $(RMD_FILE) $(BASIC_REG_RESULTS_FILE) $(BASIC_BY_SUB_REG_RESULTS_FILE) $(RI_REG_RESULTS_FILE) $(RI_BY_PATH_REG_RESULTS_FILE) $(OUTCOME_LABELS_FILE)
	@mkdir -p $(OUT_DIR)
	@mkdir -p $(PAPER_OUT_DIR)
	$(R_script) -e "rmarkdown::render(input = '$(RMD_FILE)')"
	@cp $(OUT_DIR)/*up_to_date.tex $(PAPER_OUT_DIR)

.PHONY: all clean
.DEFAULT_GOAL=all

all: $(OUT_FILE)

clean:
	rm -rf $(OUT_DIR)/*up_to_date*
